1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import com.google.common.annotations.GwtCompatible;
20 import com.google.common.annotations.GwtIncompatible;
21
22 import java.io.IOException;
23 import java.io.ObjectInputStream;
24 import java.io.ObjectOutputStream;
25 import java.util.HashMap;
26
27
28
29
30
31
32
33
34 @GwtCompatible(serializable = true, emulated = true)
35 public final class HashMultiset<E> extends AbstractMapBasedMultiset<E> {
36
37
38
39
40
41 public static <E> HashMultiset<E> create() {
42 return new HashMultiset<E>();
43 }
44
45
46
47
48
49
50
51
52 public static <E> HashMultiset<E> create(int distinctElements) {
53 return new HashMultiset<E>(distinctElements);
54 }
55
56
57
58
59
60
61
62
63
64 public static <E> HashMultiset<E> create(Iterable<? extends E> elements) {
65 HashMultiset<E> multiset =
66 create(Multisets.inferDistinctElements(elements));
67 Iterables.addAll(multiset, elements);
68 return multiset;
69 }
70
71 private HashMultiset() {
72 super(new HashMap<E, Count>());
73 }
74
75 private HashMultiset(int distinctElements) {
76 super(Maps.<E, Count>newHashMapWithExpectedSize(distinctElements));
77 }
78
79
80
81
82
83 @GwtIncompatible("java.io.ObjectOutputStream")
84 private void writeObject(ObjectOutputStream stream) throws IOException {
85 stream.defaultWriteObject();
86 Serialization.writeMultiset(this, stream);
87 }
88
89 @GwtIncompatible("java.io.ObjectInputStream")
90 private void readObject(ObjectInputStream stream)
91 throws IOException, ClassNotFoundException {
92 stream.defaultReadObject();
93 int distinctElements = Serialization.readCount(stream);
94 setBackingMap(
95 Maps.<E, Count>newHashMapWithExpectedSize(distinctElements));
96 Serialization.populateMultiset(this, stream, distinctElements);
97 }
98
99 @GwtIncompatible("Not needed in emulated source.")
100 private static final long serialVersionUID = 0;
101 }